//
//  WHTransNumberCell.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/6.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHTransNumberCell.h"

@interface WHTransNumberCell ()

@property (nonatomic, strong) UIButton *scanBtn;

@end

@implementation WHTransNumberCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    [self.contentView addSubview:({
        _scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_scanBtn setImage:IMAGE_NAMED(@"scan_icon") forState:UIControlStateNormal];
        _scanBtn;
    })];
    [_scanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(kRealwidth(55));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_equalTo(self.contentView.mas_right);
    }];
    
    [self.contentView addSubview:({
        _inputTextField = [[UITextField alloc] init];
        _inputTextField.font = SYSTEMFONT(kRealwidth(16));
        _inputTextField.textColor = CFontTitleBlackColor;
        _inputTextField;
    })];
    
    [_inputTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(kRealwidth(15));
        make.right.mas_equalTo(_scanBtn.mas_left).offset(-kRealwidth(15));
        make.height.mas_equalTo(self.contentView.mas_height);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    
    kWeakSelf(self);
    self.inputTextField.keyboardType = UIKeyboardTypeASCIICapable;
    self.inputTextField.yb_inputCP = YBInputControlProfile.creat.set_maxLength(40).set_regularStr(@"^[a-zA-Z0-9]{0,40}$").set_textChanged(^(id obj) {
        if (weakself.textChangeBlock) {
            weakself.textChangeBlock([obj valueForKey:@"text"]);
        }
    });
    [_scanBtn addTarget:self action:@selector(scan:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setInputTextPlaceHolder:(NSString *)placeHolderStr {
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:placeHolderStr attributes:@{NSForegroundColorAttributeName:CFontContentLightGrayColor, NSFontAttributeName:self.inputTextField.font}];
    self.inputTextField.attributedPlaceholder = attrString;
}

- (void)scan:(UIButton *)button {
    if (self.beginScan) {
        self.beginScan();
    }
}

@end
